<template>
  <section class="my-runlegdetail">
    <div class="status flex flex-between flex-middle">
      <span class="font1">任务状态</span>
      <span class="font1" v-if="info.taskOrder.orderStatus == 1">待接单</span>
      <span class="font1" v-else-if="info.taskOrder.orderStatus == 2">已接单</span>
      <span class="font1" v-else-if="info.taskOrder.orderStatus == 3">开始任务</span>
      <span class="font1" v-else-if="info.taskOrder.orderStatus == 4">完成任务</span>
      <span class="font1" v-else-if="info.taskOrder.orderStatus == 5">用户确认完成</span>
    </div>
    <div class="info">
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon9.png" alt />
            <span class="font1">任务类型</span>
          </van-col>
          <van-col span="14">
            <span class="font1">跑腿</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon3.png" alt />
            <span class="font1">任务名称</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskOrder.taskName}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon4.png" alt />
            <span class="font1">任务金额</span>
          </van-col>
          <van-col span="14">
            <span class="price">{{info.taskOrder.orderAmt}}</span>
            <span class="font1">元</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon7.png" alt />
            <span class="font1">联系人</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskOrder.linkMan}}</span>
          </van-col>
        </van-row>
      </div>
      <div v-if="info.taskOrder.linkTel">
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon8.png" alt />
            <span class="font1">联系电话</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskOrder.linkTel}}</span>
          </van-col>
        </van-row>
      </div>
    </div>
    <div class="info">
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon9.png" alt />
            <span class="font1">订单号</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskOrder.orderId}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon3.png" alt />
            <span class="font1">下单时间</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskOrder.orderTime}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon7.png" alt />
            <span class="font1">接单时间</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskOrder.taskBeginTime}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" src="/static/images/errand/icon8.png" alt />
            <span class="font1">接单人</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskOrder.nickName}}</span>
          </van-col>
        </van-row>
      </div>
    </div>
    <div class="place">
      <div>
        <img class="icon" src="/static/images/errand/icon2.png" alt />
        <span class="font1">任务地点</span>
      </div>
      <div class="det">
        <div class="font1">{{info.taskOrder.taskAreaId + info.taskOrder.taskDtlAddr}}</div>
        <!-- <div class="desc">湖北省武汉市武昌区</div> -->
      </div>
    </div>
    <div class="place">
      <div>
        <img class="icon" src="/static/images/errand/icon1.png" alt />
        <span class="font1">收货地点</span>
      </div>
      <div class="det">
        <div class="font1">{{info.taskOrder.taskReceiveAreaId + info.taskOrder.taskReceiveDtlAddr}}</div>
        <!-- <div class="desc">湖北省武汉市武昌区</div> -->
      </div>
    </div>
    <div class="info">
      <div class="flex flex-between flex-middle">
        <div>
          <img class="icon" src="/static/images/errand/icon6.png" alt />
          <span class="font1">任务日期</span>
        </div>
        <span class="time">{{info.taskOrder.taskDate}}</span>
      </div>
      <div class="flex flex-between flex-middle">
        <div>
          <img class="icon" src="/static/images/errand/icon5.png" alt />
          <span class="font1">任务时间</span>
        </div>
        <span class="time">{{info.taskOrder.taskBeginTime}}</span>
      </div>
    </div>
    <!-- 备注 -->
    <div class="remark">
      <van-row>
        <van-col span="3">
          <span class="font1">备注:</span>
        </van-col>
        <van-col span="21">
          <span class="font1">{{info.taskOrder.taskRemark}}</span>
        </van-col>
      </van-row>
    </div>
    <!-- 参考图片 -->
    <div class="reference">
      <div class="font1">任务参考图片</div>
      <div class="imgs">
        <img :src="item.imageUrl" v-for="item in info.taskOrderImageList" :key="item" @click="preImg(item.imageUrl)"/>
      </div>
    </div>
    <div class="flex btns">
      <button v-if="info.taskOrder.orderStatus != 1" class="btn contact" @click="goim(info.taskOrder.receiveMemberId)">联系骑手</button>
      <button
        class="btn confirm"
        v-if="info.taskOrder.orderStatus == 4"
        @click="makeMyTaskOrder(orderId,1)"
      >确认完成</button>
      <button
        class="btn del"
        v-if="info.taskOrder.orderStatus == 1"
        @click="makeMyTaskOrder(orderId,2)"
      >删除</button>
      <button
        class="btn cancel"
        v-if="info.taskOrder.orderStatus == 1 || info.taskOrder.orderStatus == 2"
        @click="makeMyTaskOrder(orderId,3)"
      >取消</button>
    </div>
  </section>
</template>
<script>
export default {
  data() {
    return {
      orderId: "",
      info: "",
      optionKeys: {
        1: {
          title: '确认完成',
          desc: '您确定完成吗？'
        },
        2: {
          title: '删除',
          desc: '您确定删除吗？'
        },
        3: {
          title: '取消',
          desc: '您确定取消吗'
        },
      }
    };
  },
  onLoad(e) {
    this.orderId = e.id ? e.id : "201909030000002010451247";
    this.getTaskMyOrderDtl();
  },
  methods: {
    preImg(url){
      console.log(url);
      console.log(this.info.taskOrderImageList)
      let urls = this.info.taskOrderImageList.map((item)=>{
        return item.imageUrl
      })
      wx.previewImage({
        current: url, // 当前显示图片的http链接
        urls // 需要预览的图片http链接列表
      })
    },
    goim(id) {
      this.$tim(id)
      // let ids = "FT_" + id;
      // let cid= this.TIM.TYPES.CONV_C2C + ids
      // console.log(cid)
      // this.$store.commit("resetCurrentConversation");
      // wx.$app.getConversationProfile(cid).then(res => {
      //   this.$store.commit("updateCurrentConversation", res.data.conversation);
      //   this.$store.dispatch("getMessageList");
      //   let url = `/pages/tim/chat/main?toAccount=${ids}`;
      //   wx.navigateTo({ url });
      // });
    },
    phoneCall(phoneNumber) {
      wx.makePhoneCall({
        phoneNumber //仅为示例，并非真实的电话号码
      });
    },
    getTaskMyOrderDtl() {
      this.$api.getTaskMyOrderDtl({ orderId: this.orderId }).then(res => {
        this.info = res.data;
        this.$set(
          this.info.taskOrder,
          "orderTime",
          this.formatDate(res.data.taskOrder.orderTime, "Y-D-M h:s")
        );
        this.$set(
          this.info.taskOrder,
          "taskDate",
          this.formatDate(res.data.taskOrder.taskDate)
        );
      });
    },
    //操作任务1.确认完成 2.删除 3.取消
    makeMyTaskOrder(orderId, type) {
      const self = this;
      const obj = this.optionKeys[type];
      wx.showModal({
        title: obj.title, //提示的标题,
        content: obj.desc, //提示的内容,
        showCancel: true, //是否显示取消按钮,
        cancelText: "取消", //取消按钮的文字，默认为取消，最多 4 个字符,
        cancelColor: "#000000", //取消按钮的文字颜色,
        confirmText: "确定", //确定按钮的文字，默认为取消，最多 4 个字符,
        confirmColor: "#3BB8FD", //确定按钮的文字颜色,
        success: res => {
          if (res.confirm) {
            self.$api.makeMyTaskOrder({ orderId, type }).then(res => {
              if (res.code == 1) {
                wx.showToast({
                  title: res.msg, //提示的内容,
                  icon: "none", //图标,
                  duration: 2000, //延迟时间,
                  mask: true, //显示透明蒙层，防止触摸穿透,
                  success: res => {}
                });
              } else {
                wx.showToast({
                  title: res.msg, //提示的内容,
                  icon: "none", //图标,
                  duration: 2000, //延迟时间,
                  mask: true, //显示透明蒙层，防止触摸穿透,
                  success: res => {
                    wx.navigateBack({
                      delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
                    });
                  }
                });
              }
            });
          } else if (res.cancel) {
            console.log("用户点击取消");
          }
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.my-runlegdetail {
  .status {
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    margin: 15px 10px;
    padding: 20px 15px;
  }
  .info {
    margin: 15px 10px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    & > div {
      padding: 20px 0;
    }
    & > div:not(:last-child) {
      border-bottom: 1px solid #f2f2f2;
    }
    .icon {
      margin-right: 6px;
    }
    .price {
      font-size: 15px;
      font-family: PingFang;
      font-weight: 500;
      color: rgba(59, 184, 253, 1);
      line-height: 13px;
      vertical-align: middle;
    }
    .time {
      font-size: 12px;
      font-family: DIN;
      font-weight: 500;
      color: rgba(46, 46, 46, 1);
      line-height: 13px;
    }
  }
  .place {
    margin: 15px 10px;
    .font1 {
      margin-left: 6px;
    }
    .det {
      margin-top: 8px;
      padding: 20px;
      background: rgba(255, 255, 255, 1);
      border-radius: 5px;
      .font1 {
        margin-left: 0;
      }
      .desc {
        font-size: 12px;
        font-family: PingFang;
        font-weight: 500;
        color: rgba(193, 196, 201, 1);
        line-height: 13px;
        margin-top: 20px;
      }
    }
  }
  .remark {
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    margin: 15px 10px;
    padding: 20px 10px;
    .font1 {
      line-height: 24px;
    }
  }
  .btns {
    padding-bottom: 15px;
    .btn {
      width: 75px;
      height: 34px;
      line-height: 34px;
      padding: 0;
      text-align: center;
      background: rgba(59, 184, 253, 1);
      border-radius: 5px;
      font-size: 15px;
      font-family: PingFang;
      font-weight: 500;
      color: rgba(255, 255, 255, 1);
    }
    .contact,
    .confirm,
    .del {
      border: 1px solid rgba(59, 184, 253, 1);
      background: white;
      color: #3bb8fd;
    }
  }
  .reference {
    padding: 15px 10px;
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    margin: 15px 10px;
    .font1 {
      margin-bottom: 15px;
    }
    .imgs {
      img {
        width: 60px;
        height: 60px;
        border-radius: 1px;
        &:not(:last-child) {
          margin-right: 9px;
        }
      }
    }
  }
  .font1 {
    font-size: 13px;
    font-family: PingFang;
    font-weight: 500;
    color: rgba(46, 46, 46, 1);
    line-height: 13px;
    vertical-align: middle;
  }
  .icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
  }
}
</style>
<style lang="scss">
page {
  background: #f7f7f7;
}
</style>